package itsm.isperp.module.service.incident;

import itsm.isperp.framework.data.mybatis.dao.TreeNodeMapper;
import itsm.isperp.framework.service.TreeNodeService;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.entity.incident.IcdCategory;
import itsm.isperp.module.repository.app.AppUserMapper;
import itsm.isperp.module.repository.incident.IcdCategoryMapper;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class IcdCategoryService extends TreeNodeService<IcdCategory> {

	@Autowired
	protected IcdCategoryMapper icdCategoryMapper;

	@Autowired
	protected IcdCategoryRelamembersService icdCategoryRelamembersService;

	@Autowired
	protected AppUserMapper appUserMapper;

	@Override
	public TreeNodeMapper<IcdCategory> getRepository() {
		return this.icdCategoryMapper;
	}

	 

	public boolean memberExistsInCategory(String username, String category_id) {

		JqGridRequest req = new JqGridRequest();
		req.isOnlyQueryCount();
		req.addFilterRule("category_id", JqGridFilterRuleOp.eq, category_id);
		req.addFilterRule("users_name", JqGridFilterRuleOp.eq, username);
		long l = icdCategoryRelamembersService.findAllDetailByRequest(req)
				.getTotalElements();
		return l > 0;
	}

	/**
	 * 获取事件分类关联人员列表
	 * 
	 * @param categoryId
	 *            事件分类Id
	 * @return 关联工程师
	 */
	public List<Map<String, Object>> getIcdCategoryRelamembers(String categoryId) {

		return this.icdCategoryRelamembersService
				.findAllMemberByCategoryId(categoryId);

	}


}
